@rem Do not use "echo off" to not affect any child calls.
@rem setlocal

@rem move bat file drive folder
@rem http://snoopybox.co.kr/1404
@pushd %~dp0

cd ..\..

set RUBY_DIR=F:\opt\Ruby187
set SCM_DIR=F:\opt\scm
set PATH=%SCM_DIR%\git\cmd;%RUBY_DIR%\bin;%RUBY_DIR%\lib\ruby\gems\1.8\bin;%SCM_DIR%\TortoiseSVN\bin;C:\tools\PlasticSCM4\client;f:\opt\devkit\bin;f:\opt\devkit\mingw\bin;f:\opt\vendor\imagemagick;%PATH%

ruby -v
@if errorlevel 1 (
@echo can not find ruby in path:%PATH%
goto :exit
)

@rem gem -v
@rem @if errorlevel 1 (
@rem gem update --system
@rem )

@rem make Gemfile.local file
@echo source 'http://rubygems.org'> Gemfile.local
@rem add blank line
@echo.>> Gemfile.local
@echo gem "mysql2", "~>0.3.11">> Gemfile.local
@echo gem "thin", "~> 1.5.0">> Gemfile.local

set CPATH=F:\opt\vendor\imagemagick\include
set LIBRARY_PATH=F:\opt\vendor\imagemagick\lib

@cmd /C bundle install --without postgresql sqlite --binstubs
if errorlevel 1 goto :exit

@rem rake -v 
@rem @if errorlevel 1 (
@rem gem install rake
@rem )

@rem rails -v
@rem @if errorlevel 1 (
@rem gem install rails -v=3.2.8
@rem )

:setup
@cmd /C rake generate_secret_token
@cmd /C rake db:migrate RAILS_ENV="production"
@set REDMINE_LANG=en
cmd /C rake redmine:load_default_data RAILS_ENV="production"

@cmd /C rake db:migrate RAILS_ENV="development"
cmd /C rake redmine:load_default_data RAILS_ENV="development"

@cmd /C rake db:migrate RAILS_ENV="test"
cmd /C rake redmine:load_default_data RAILS_ENV="test"

@echo done.
goto :exit

:exit
@echo .